// Authority.h : Declaration of the CAuthority

#ifndef __AUTHORITY_H_
#define __AUTHORITY_H_

#include "resource.h"       // main symbols
#include "eDasResultCode.h"

#include "Roles.h"

#include "StorageDatabase.h"

/////////////////////////////////////////////////////////////////////////////
// CAuthority
class ATL_NO_VTABLE CAuthority : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CAuthority, &CLSID_Authority>,
	public IDispatchImpl<IAuthority, &IID_IAuthority, &LIBID_ACTIVCARDLib>
{
// Constructions
public:
	CAuthority();
// Attributions
public:
	CStorageDatabase m_storage;
private:
//	CGateways m_gateways; // Therefor,the management of gateways are in the IAuthenticaton,this object couldn't synchronized.
	CRoles m_roles;
// Functions
private:
	BOOL IsAccept(const CString &strUserName, const CString &strGateway);
	CStringItemsArray GetAdmittances(const CStringItemsArray & arrRoles);

public:
DECLARE_REGISTRY_RESOURCEID(IDR_AUTHORITY)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CAuthority)
	COM_INTERFACE_ENTRY(IAuthority)
	COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

// IAuthority
public:
	STDMETHOD(CheckGateway)(BSTR bstrUserName, BSTR bstrGateway, long *ret);
	STDMETHOD(SetUserRole)(/*[in]*/ BSTR strUserName, /*[in]*/ BSTR bstrRolesNames, /*[out,retval]*/ long * ret);
	STDMETHOD(SetUserGroupDefaultRole)(/*[in]*/ BSTR bstrGroupName, /*[in]*/ BSTR bstrDefaultRolesNames, /*[out,retval]*/ long * ret);
	STDMETHOD(GetRoles)(/*[out]*/ BSTR * pbstrRoles, /*[out,retval]*/ long * ret);
	STDMETHOD(DeleteRole)(/*[in]*/ BSTR bstrRoleName, /*[out,retval]*/ long * ret);
	STDMETHOD(UpdateRole)(/*[in]*/ BSTR bstrOriginalRoleName, /*[in]*/ BSTR bstrNewRoleName, /*[in]*/ BSTR bstrAdmittanceGateways, /*[out,retval]*/ long * ret);
	STDMETHOD(AddRole)(/*[in]*/ BSTR bstrRoleName, /*[in]*/ BSTR bstrAdmittanceGateways, /*[out,retval]*/ long * ret);
};

#endif //__AUTHORITY_H_
